<template>
  <div class="bank-card-management">
    <el-card>
      <el-form ref="ruleForm" :model="ruleForm" :inline="true" label-width="100px" class="ruleForm">
        <el-form-item label="买手ID：" prop="buyerId">
          <el-input v-model="ruleForm.buyerId" />
        </el-form-item>
        <el-form-item label="审核状态：" prop="examineStatus">
          <el-select v-model="ruleForm.examineStatus">
            <el-option label="全部" value="" />
            <el-option label="审核中" value="IN_REVIEW" />
            <el-option label="审核通过" value="VERIFIED" />
            <el-option label="审核不通过" value="REJECTED" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table
        v-loading="isLoading"
        :data="tableData"
        border
        style="width: 100%"
      >
        <el-table-column
          fixed
          prop="user_id"
          label="买手ID"
          width="120"
          align="center"
        />
        <el-table-column
          prop="bank_account"
          label="银行卡号"
          width="250"
          align="center"
        />
        <el-table-column
          prop="bank_username"
          label="开户人"
          width="120"
          align="center"
        />
        <el-table-column
          prop="bank_name"
          label="开户行"
          width="180"
          align="center"
        />
        <el-table-column
          prop="subbranch"
          label="开户支行"
          width="180"
          align="center"
        />
        <el-table-column
          prop="bank_region"
          label="开户地区"
          width="180"
          align="center"
        />
        <el-table-column
          prop="examine_explain"
          label="审核说明"
          align="center"
        />
        <el-table-column
            label="状态"
          align="center"
          width="120"
          >
            <template slot-scope="scope">
              {{ scope.row.examine_status | getExamineStatus }}
            </template>
          </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <el-button v-if="scope.row.examine_status === 'REJECTED' || scope.row.examine_status === 'IN_REVIEW'" type="text" size="small" @click="handleClick(scope.row, scope.$index, 'VERIFIED')">通过</el-button>
            <el-button v-if="scope.row.examine_status === 'VERIFIED' || scope.row.examine_status === 'IN_REVIEW'" type="text" size="small" @click="handleClick(scope.row, scope.$index, 'REJECTED')">不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :page-size="10"
        layout="total, prev, pager, next, jumper"
        :total="total"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>
<script>
import { buyerBankCardSearch, buyerBankCardExamine } from '@/api/user'
// import inputImage from '@/components/_inputImage'
export default {
  // components: {
  //   inputImage
  // },
  filters: {
    getExamineStatus(status) {
      let StringType = ''
      switch(status) {
        case 'IN_REVIEW' :
          StringType = '审核中'
          break
        case 'VERIFIED' :
          StringType = '审核通过'
          break
        case 'REJECTED' :
          StringType = '审核不通过'
          break
      }
      return StringType
    }
  },
  data() {
    return {
      isLoading: false,
      tableData: [],
      ruleForm: {
        examineStatus: '', // IN_REVIEW-审核中，VERIFIED-审核通过，REJECTED-审核不通过
        pageNumber: 1
      },
      total: 0
    }
  },
  mounted() {
    this.buyerBankCardSearch()
  },
  methods: {
    buyerBankCardSearch() {
      this.isLoading = true
      buyerBankCardSearch(this.ruleForm).then(res => {
        console.log(res)
        this.tableData = res.list
        this.total = res.totalRow
        this.isLoading = false
      }).catch(() => {
        this.isLoading = false
      })
    },
    handleClick(row, index, type) {
      this.$prompt(`是否${type === 'VERIFIED' ? '通过' : '不通过'}该银行卡的审核？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        buyerBankCardExamine({
          id: row.id,
          examineStatus: type,
          examineExplain: value
        }).then(res => {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.tableData[index].examine_status = type
          this.tableData[index].examine_explain = value
        })
      })
    },
    onSubmit() {
      this.ruleForm.pageNumber = 1
      this.buyerBankCardSearch()
    },
    handleCurrentChange(page) {
      this.ruleForm.pageNumber = page
      this.buyerBankCardSearch()
    }
  }
}
</script>
<style lang="scss">
  .bank-card-management{
    .el-card{
      .el-form{
        .el-input{
          width: 200px;
        }
        .el-select{
          width: 200px;
        }
      }
    }
  }
</style>
